package com.fy.spring.controller;


import com.fy.spring.entities.CommonResult;
import com.fy.spring.entities.Payment;
import com.fy.spring.serivce.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/payment")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @PostMapping("/create")
    public CommonResult create(@RequestBody Payment payment) {
        int res = paymentService.create(payment);
        return res > 0 ?
                new CommonResult(200, "插入数据库成功", res) :
                new CommonResult(444, "插入数据库失败", null);
    }


    @GetMapping(value = "/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") int id) {
        Payment payment = paymentService.getPaymentById(id);
        return null != payment ?
                new CommonResult(200, "查询数据成功", payment) :
                new CommonResult(444, "查询数据失败", null);
    }
}
